
using System;
using System.Threading;
using System.Collections.Generic;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MonoTouch.ObjCRuntime;  

namespace test14
{
	public class Application
	{
		static void Main (string[] args)
		{
			UIApplication.Main (args);
		}
	}

	// The name AppDelegate is referenced in the MainWindow.xib file.
	public partial class AppDelegate : UIApplicationDelegate
	{
		// This method is invoked when the application has loaded its UI and its ready to run
		public override bool FinishedLaunching (UIApplication app, NSDictionary options)
		{
			// If you have defined a view, add it here:
			// window.AddSubview (navigationController.View);
			
			window.MakeKeyAndVisible ();
			
			NSNetService s = new NSNetService("", "_senk._tcp", "", 2000);
			s.Delegate = new MyNetServiceDelegate();
			s.Publish();
			
			Thread.Sleep(3000);
			
			NSNetServiceBrowser b = new NSNetServiceBrowser();
			b.Delegate = new MyNetServiceBrowserDelegate();
			b.SearchForServices(new NSString("_senk._tcp"), new NSString(""));
			
			return true;
		}

		// This method is required in iPhoneOS 3.0
		public override void OnActivated (UIApplication application)
		{
		}
	}
	
	public class MyNetServiceBrowserDelegate : NSNetServiceBrowserDelegate
	{
		public override void FoundService (NSNetServiceBrowser netServiceBrowser, NSNetService netService, bool moreServicesComing)
		{
			Console.WriteLine("Found service."); 
			Console.WriteLine(netService); 
			Console.WriteLine(netServiceBrowser);
		}
		
		public override void NotSearched (NSNetServiceBrowser netServiceBrowser, NSDictionary errorInfo)
		{
			Console.WriteLine("Not searched.");
		}

		public override void SearchStarted (NSNetServiceBrowser netServiceBrowser)
		{
			Console.WriteLine("Search started.");
		}

	}
	
	public class MyNetServiceDelegate : NSNetServiceDelegate
	{
		public override void WillPublish(NSNetService sender)
		{
			Console.WriteLine("Will Publish");
		}
		
		public override void Published (NSNetService sender)
		{
			Console.WriteLine("Did Publish");
		}
	}
}
